<script>

function compileRegExp(xregexp, name) {
  let regexp = xregexp[name].source.replace(/\<([^>]+)\>/g, (str, $1) => {
    return compileRegExp(xregexp, $1)
  })
  return regexp
}

let regexp = compileRegExp({
  InputElement: /<Whitespace>|<LineTerminator>|<Comments>|<Token>/,
  Whitespace: / /,
  LineTerminator: /\n/,
  Comments: /\/\*([^*]\*[^\/])*\*\/|\/\/[^\n]*/,
  Token: /<Literal>|<Keywords>|<Identifer>|<Punctuator>/,
  Literal: /<NumbericLiteral>|<BooleanLiteral>|<StringLiteral>|<NullnLiteral>/,
  NumbericLiteral: /([1-9][0-9]*|0)\.[0-9]*|\.[0-9]+/,
  BooleanLiteral: /true|false/,
  StringLiteral: /\"([^"\n])\"/,
}, 'InputElement')

console.log(new RegExp(regexp, 'g'))

function scan(str) {
  let regexp = / |\n|\/\*([^*]|\*[^\/])*\*\/|\/\/[^\n]*|[1-9][0-9]*|0/g
  while(regexp.lastIndex < str.length) {
    let r = regexp.exec(str)
  }
}

scan(`
  13
  5
  7
  //hellow world
  /*hellow world*/
`)

</script>